#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <BEntry>
#include <BIcon>
#include <BImage>
#include <BButton>
#include <BLineEdit>
#include <BFileDialog>
#include <BListWidget>
#include <BTabWidget>
#include <BMenuBar>
#include <BStatusBar>
#include <BHBoxLayout>
#include <BVBoxLayout>
#include <BMainWindow>

#include "CustomTagDialog.h"
#include "PathSettingDialog.h"
#include "CheckDialog.h"
#include "PropertyBoard.h"

class MainWindow : public BMainWindow
{
	BOBJECT(MainWindow);
public:
	MainWindow();
	~MainWindow();

	bool openHtmlFile(const BString& htmlFileName);

protected:
	void initMenuBar();

	bool checkHeadFile(BListItem* item);
	bool freshHtmlFile(const BString& htmlFileName);
	void signTitleChanged(BWidget* widget, bool changed);
	void freshHeadItemIcons(BListItem* item);

	void resetTreeWidget();
	BTreeItem* createTreeItem(BHtmlItem* htmlItem);
	void refreshTreeItem(BHtmlItem* htmlItem);
	void freshTreeItemIcon(BTreeItem* item);
	void paintLinks(BHtmlItem* item, BPainter& painter);
	void paintMarks(BHtmlItem* item, BPainter& painter);
	void paintUnderLine(BHtmlItem* item, BPainter& painter);

protected:
	void slotConfigChanged();

	void slotSaveShortcutTriggered(BObject* object, const BValue& value);
	void slotSaveAllShortcutTriggered(BObject* object, const BValue& value);

	void slotOpenDocument();
	void slotSaveDocument();
	void slotSaveAllDocument();
	void slotLanguageCurrentChanged(BObject* object, const BValue& value);

	void slotHideButtonClicked();
	void slotTabWidgetHide(BListWidget* listWidget, const BValue& value);

	void slotFreshButtonClicked(BButton* button);
	void slotHeadItemRightClicked(BObject* object, const BValue& value);
	void slotHeadItemDoubleClicked(BObject* object, const BValue& value);
	void slotHeadListWidgetFramed(BListWidget* listWidget, const BValue& value);

	void slotTabWidgetFramed(BTabWidget* tabWidget, const BValue& value);
	void slotTabCurrentChanged(BObject* object, const BValue& value);
	void slotTabClicked(BObject* object, BValue& value);
	void slotTabRightClicked(BObject* object, BValue& value);
	void slotTabClosing(BObject* object, BValue& value);
	void slotTabHovered(BObject* object, BValue& value);

	void slotHtmlTreeItemClicked(BObject* object, BValue& value);
	void slotHtmlTreeWidgetKeyPress(BObject* object, BValue& value);
	void slotPropertyBoardChanged(BObject* object, BValue& value);

	void slotEditableButtonToggled(BObject* object, const BValue& value);
	void slotViewMenuTriggered(BObject* object, const BValue& value);
	void slotMenuStyled(BMenu* menu, const BValue& value);

	void slotRemoveActionTriggered(BObject* object, const BValue& value);
	void slotCutActionTriggered(BObject* object, const BValue& value);
	void slotCopyActionTriggered(BObject* object, const BValue& value);
	void slotPasteActionTriggered(BObject* object, const BValue& value);

	void slotHeadListMenuTrigger(BObject* object, const BValue& value);
	void slotTableMenuTrigger(BObject* object, const BValue& value);
	void slotTabMenuTrigger(BObject* object, const BValue& value);

	void slotHtmlWidgetFramed(BHtmlWidget* htmlWidget, const BValue& value);
	void slotHtmlItemSelected(BObject* object, const BValue& value);
	void slotHtmlItemClicked(BHtmlWidget* htmlWidget, const BValue& value);
	void slotHtmlItemRightClicked(BHtmlWidget* htmlWidget, const BValue& value);
	void slotHtmlItemChanged(BHtmlWidget* htmlWidget, const BValue& value);

	void slotMenuAddActionClicked(BObject* object, const BValue& value);
	void slotMenuPrependActionClicked(BObject* object, const BValue& value);
	void slotMenuAppendActionClicked(BObject* object, const BValue& value);
	void slotMenuConvertActionClicked(BObject* object, const BValue& value);

protected:
	virtual void closeEvent(const BEvent& event);

	virtual void updateEvent(const BEvent& event);

	virtual void styleEvent(const BEvent& event);

private:
	BButton*			_openButton;
	BButton*			_saveButton;
	BButton*			_saveAllButton;
	BButton*			_prevButton;
	BButton*			_nextButton;
	BButton*			_editableButton;
	BHBoxLayout*		_editLayout;
	BMenuBar*			_menuBar;
	BButton*			_viewMenuButton;
	BComboBox*			_languageComboBox;

	BTabWidget*			_tabWidget;
	BButton*			_hideButton;
	BListWidget*		_fileListWidget;
	BButton*			_itemStateButton;
	BButton*			_headFreshButton;
	BTreeWidget*		_htmlTreeWidget;
	BTabWidget*			_pageTabWidget;
	PropertyBoard*		_propertyBoard;
	BStatusBar*			_statusBar;

	PathSettingDialog*	_pathSettingDialog;
	BFileDialog*		_fileDialog;
	CheckDialog*		_checkDialog;
	CustomTagDialog*	_customTagDialog;

	BMenu*				_fileListMenu;
	BMenu*				_pageMenu;
	BMenu*				_tableMenu;
	BMenu*				_tabMenu;
	BAction*			_removeAction;
	BAction*			_cutAction;
	BAction*			_copyAction;
	BAction*			_pasteAction;

	BFolder				_includeFolder;
	BFolder				_manualFolder;
	BReal				_selectTick;

	BImageHolder		_normalImage;
	BImageHolder		_dirtyImage;
	BImageHolder		_emptyImage;

	BIconHolder			_linkIcon;
	BIconHolder			_htmlIcon;
	BIconHolder			_textIcon;
	BIconHolder			_treeIcon;
};

#endif